package com.xsmart.oa.services;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.oa.dao.DistributeCountReportDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuqinyuan
 */
@Service
public class DistributeCountReportService {
    @Autowired
    DistributeCountReportDao distributeCountReportDao;

    /** 查询分销商统计报表
     * @param requestBean
     * @return
     */
    public ResponseBean queryCountReport(RequestBean requestBean){
        String nickName = requestBean.getRequestParamString("nick_name");
        String orderStatus = requestBean.getRequestParamString("order_status");
        String shippingStatus = requestBean.getRequestParamString("shipping_status");
        String payStatus = requestBean.getRequestParamString("pay_status");
        List addTime = (List) requestBean.getRequestParam("add_time");
        String timeType = requestBean.getRequestParamString("timeType");
        Map paramMap = new HashMap<>();
        if (addTime != null && addTime.size() > 0){
            paramMap.put("addStartTime",addTime.get(0));
            paramMap.put("addEndTime",addTime.get(1));
        }

        paramMap.put("nickName",nickName);
        paramMap.put("orderStatus",orderStatus);
        paramMap.put("shippingStatus",shippingStatus);
        paramMap.put("payStatus",payStatus);
        paramMap.put("timeType",timeType);
        ResponseBean responseBean =requestBean.getResponseBean();
        int currentPage=requestBean.getRequestParamInteger("currentPage",1);
        int pageSize=requestBean.getRequestParamInteger("pageSize",10);
        Page<Map<String,Object>> page=new Page<>(currentPage,pageSize);
        page.setRecords(distributeCountReportDao.queryCountReport(page,paramMap));
        responseBean.addResultPageItem("distributeCountReport",page);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**查询分销商报表销售商品清单
     * @param requestBean
     * @return
     */
    public ResponseBean queryCountReportGoodsList(RequestBean requestBean) {
        Integer shopId = requestBean.getRequestParamInteger("shop_id");
        String nickName = requestBean.getRequestParamString("nick_name");
        String orderStatus = requestBean.getRequestParamString("order_status");
        String shippingStatus = requestBean.getRequestParamString("shipping_status");
        String payStatus = requestBean.getRequestParamString("pay_status");
        List addTime = (List) requestBean.getRequestParam("add_time");
        String timeType = requestBean.getRequestParamString("timeType");
        Map paramMap = new HashMap<>();
        if (addTime != null && addTime.size() > 0){
            paramMap.put("addStartTime",addTime.get(0));
            paramMap.put("addEndTime",addTime.get(1));
        }
        paramMap.put("shopId",shopId);
        paramMap.put("nickName",nickName);
        paramMap.put("orderStatus",orderStatus);
        paramMap.put("shippingStatus",shippingStatus);
        paramMap.put("payStatus",payStatus);
        paramMap.put("timeType",timeType);

        ResponseBean responseBean = requestBean.getResponseBean();
        int currentPage = requestBean.getRequestParamInteger("currentPage", 1);
        int pageSize = requestBean.getRequestParamInteger("pageSize", 10);
        Page<Map<String, Object>> page = new Page<>(currentPage, pageSize);
        page.setRecords(distributeCountReportDao.queryCountReportGoodsList(page,paramMap));
        responseBean.addResultPageItem("distributeCountReportGoodList", page);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }




    }
